package com.you.weixinpay.utils;

import com.you.weixinpay.enums.PaymentType;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * 订单号工具类
 *
 * @author qy
 * @since 1.0
 */
public class OrderNoUtils {

    private static final String WX = "WX_";
    private static final String ALI = "ALI_";

    /**
     * 获取类型
     */
    public static String getType(String paymentType) {
        return paymentType.equals(PaymentType.WXPAY.getType()) ? WX : ALI;
    }

    /**
     * 获取订单编号
     * 示例：ORDER_20250620125918452
     */
    public static String getOrderNo() {
        return "ORDER_" + getNo();
    }

    /**
     * 获取退款单编号
     * 示例：REFUND_20250620231800941
     */
    public static String getRefundNo() {
        return "REFUND_" + getNo();
    }

    /**
     * 获取编号
     */
    public static String getNo() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String newDate = sdf.format(new Date());
        StringBuilder result = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < 3; i++) {
            result.append(random.nextInt(10));
        }
        return newDate + result;
    }

}
